<template>
  <div class="head">
    <div class="tit">
      <button class="tex1">面单返利报表</button>
    </div>
    <div class="line" />
    <el-row>
      <el-col :span="24">
        <div class="title1">
          <el-form
            ref="form"
            style="
              display: flex;
              flex-wrap: wrap;
              margin-top: 24px;
              justify-content: space-between;
            "
            :model="form"
            label-width="80px"
          >
            <div
              style="
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
                width: 1628px;
              "
            >
              <el-form-item class="text" label="汇总层级">
                <el-select
                  v-model="form.collectType"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="日汇总" value="1" />
                  <el-option label="月汇总" value="2" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="政策对象">
                <el-select
                  v-model="form.objectType"
                  placeholder="请选择"
                  style="width: 286px"
                  @change="changeType"
                >
                  <el-option label="网点" value="1" />
                  <el-option label="大客户" value="2" />
                  <el-option label="承包区" value="3" />
                  <el-option label="U码商家" value="4" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="政策大类">
                <el-select
                  v-model="form.policyBigKind"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="主政策" value="主政策" />
                  <el-option label="叠加政策" value="叠加政策" />
                  <el-option label="季节性政策" value="季节性政策" />
                  <el-option label="淡旺季政策" value="淡旺季政策" />
                  <el-option label="考核政策" value="考核政策" />
                  <el-option label="一客价" value="一客价" />
                </el-select>
              </el-form-item>
              <el-form-item class="text" label="政策小类">
                <el-select
                  v-model="form.policySmallKind"
                  class="input"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option label="固定金额返利" value="固定金额返利" />
                  <el-option label="固定金额考核" value="固定金额考核" />
                  <el-option label="限量加收" value="限量加收" />
                  <el-option
                    label="返利加油包-有考核"
                    value="返利加油包-有考核"
                  />
                  <el-option
                    label="返利加油包-目的地考核"
                    value="返利加油包-目的地考核"
                  />
                  <el-option
                    label="返利加油包-无考核"
                    value="返利加油包-无考核"
                  />
                  <el-option label="考核加油包" value="考核加油包" />
                  <el-option label="阶梯考核" value="阶梯考核" />
                  <el-option label="通票考核" value="通票考核" />
                  <el-option label="基础考核" value="基础考核" />
                  <el-option label="多条件返利" value="多条件返利" />
                  <el-option label="增量返利" value="增量返利" />
                  <el-option label="阶梯返利" value="阶梯返利" />
                  <el-option label="通票返利" value="通票返利" />
                </el-select>
              </el-form-item>
            </div>
            <div>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">查询</el-button>
                <el-button @click="khClear">重置</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
        <div class="title1">
          <el-form
            ref="form"
            style="
              display: flex;
              justify-content: space-between;
              flex-wrap: wrap;
            "
            :model="form"
            label-width="80px"
          >
            <div
              style="
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap;
              "
              :style="{ width: width + 'px' }"
            >
              <el-form-item class="text" label="日期">
                <el-date-picker
                  v-model="value"
                  type="daterange"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  style="width: 708px"
                  @change="changeTime"
                />
              </el-form-item>
              <el-form-item class="text" label="网点名称">
                <el-select
                  :disabled="true"
                  placeholder="辽宁盘锦公司"
                  style="width: 286px"
                >
                  <el-option label="辽宁盘锦公司" value="1" />
                </el-select>
              </el-form-item>
              <el-form-item
                v-if="form.objectType === '2'"
                class="text"
                label="大客户名"
              >
                <el-select
                  v-model="form.bigClientId"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option
                    v-for="item in ClientTagList"
                    :key="item.id"
                    :label="item.clientLevel"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-form-item
                v-if="form.objectType === '3'"
                class="text"
                label="承包区名"
              >
                <el-select
                  v-model="form.contractAreaNameId"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option
                    v-for="item in ShowCoverAreaList"
                    :key="item.id"
                    :label="item.networkName"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
              <el-form-item
                v-if="form.objectType === '4'"
                class="text"
                label="U码商家名"
              >
                <el-select
                  v-model="form.ucodeMerchantId"
                  placeholder="请选择"
                  style="width: 286px"
                >
                  <el-option
                    v-for="item in UCodeList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  />
                </el-select>
              </el-form-item>
            </div>
            <div />
            <div>
              <el-form-item>
                <el-button @click="onSubmit"
                  ><i class="el-icon-upload2" />导出</el-button
                >
              </el-form-item>
            </div>
          </el-form>
        </div>
        <el-table
          :data="tableData"
          border
          max-height="734"
          :header-cell-style="{ background: '#f6f6f6' }"
          style="width: 100%"
        >
          <el-table-column
            type="index"
            width="50"
            :index="table_index"
            align="center"
          />
          <el-table-column
            prop="collectDate"
            label="结算时间"
            width="180"
            align="center"
          />
          <el-table-column
            prop="networkNameId"
            width="100"
            label="省公司编码"
            align="center"
          />
          <el-table-column
            prop="networkName.networkName"
            width="100"
            label="省公司名称"
            align="center"
          />
          <el-table-column
            v-if="form.objectType === '3'"
            width="100"
            prop="contractAreaNameId"
            label="承包区编码"
            align="center"
          />
          <el-table-column
            v-if="form.objectType === '3'"
            width="100"
            prop="contractAreaName.networkName"
            label="承包区名称"
            align="center"
          />
          <el-table-column
            v-if="form.objectType === '2'"
            prop="bigClientId"
            width="100"
            label="大客户编码"
            align="center"
          />
          <el-table-column
            v-if="form.objectType === '2'"
            width="100"
            prop="networkClient"
            label="大客户名称"
            align="center"
          />
          <el-table-column
            v-if="form.objectType === '4'"
            width="110"
            prop="ucodeMerchantId"
            label="U码商家编码"
            align="center"
          />
          <el-table-column
            v-if="form.objectType === '4'"
            width="110"
            prop="uCodeMerchant.uCodeMerchant"
            label="U码商家名称"
            align="center"
          />
          <el-table-column label="业务情况" align="center">
            <el-table-column
              prop="hcDayMax"
              label="日结算最大值"
              width="120"
              align="center"
            />
            <el-table-column
              prop="hcMonthMax"
              label="月结算最大值"
              width="120"
              align="center"
            />
            <el-table-column
              prop="hcAimNum"
              label="目标业务量"
              width="100"
              align="center"
            />
            <el-table-column
              prop="hcRate"
              label="目标达成率"
              width="100"
              align="center"
            />
          </el-table-column>
          <el-table-column label="返利" align="center">
            <el-table-column prop="rbType" label="返利类型" align="center" />
            <el-table-column prop="rbAmount" label="返利金额" align="center" />
            <el-table-column
              prop="rbPreAmount"
              label="前日返利金额"
              width="110"
              align="center"
            />
            <el-table-column prop="rbAdjust" label="返利调整" align="center" />
          </el-table-column>
          <el-table-column label="考核" align="center">
            <el-table-column prop="exType" label="考核类型" align="center" />
            <el-table-column prop="exAmount" label="考核金额" align="center" />
            <el-table-column
              prop="exPreAmount"
              label="前日考核金额"
              width="110"
              align="center"
            />
            <el-table-column prop="exAdjust" label="考核调整" align="center" />
          </el-table-column>
          <el-table-column label="手工账" align="center">
            <el-table-column
              prop="haAmount"
              label="手工账金额"
              width="100"
              align="center"
            />
            <el-table-column
              prop="haPreAmount"
              label="前日手工账金额"
              width="120"
              align="center"
            />
            <el-table-column
              prop="haAdjust"
              label="手工账调整"
              width="100"
              align="center"
            />
          </el-table-column>
          <el-table-column prop="totalAmount" label="总额" align="center" />
          <el-table-column
            prop="adjustAmount"
            label="调整总额"
            align="center"
          />
        </el-table>
        <div
          style="
            display: flex;
            justify-content: space-between;
            margin-top: 51px;
          "
        >
          <div class="title2" />
          <div class="block" style="display: flex; justify-content: flex-end">
            <el-pagination
              background
              :current-page="current"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="10"
              layout="total, prev, pager, next"
              :total="+total"
              prev-text="上一页"
              next-text="下一页"
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
            />
          </div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { NewSheetRebateApi, UCodeApi, ClientTagApi, ShowCoverAreaApi } from '@/api/HqFinancePanel'

export default {
  components: {},
  data() {
    return {
      value: '',
      form: {
        bigClientId: '',
        collectType: '',
        contractAreaNameId: '',
        endTime: '',
        networkNameId: '1',
        objectType: '',
        pageDate: {
          pageNum: 1,
          pageSize: 10
        },
        policyBigKind: '',
        policySmallKind: '',
        startTime: '',
        ucodeMerchantId: ''
      },
      tableData: [],
      current: '', // 页数
      pages: '', // 条数
      total: '', // 总数
      width: 1207,
      UCodeList: [], // U码商家名列表
      ClientTagList: [], // 大客户名列表
      ShowCoverAreaList: []// 承包区列表
    }
  },

  computed: {},

  created() {
    this.UCode()
    this.ClientTag()
    this.ShowCoverArea()
  },

  methods: {
    // 序号
    table_index(index) {
      return (this.pages - 1) * this.current + index + 1
    },
    // 选择时间
    changeTime() {
      this.form.startTime = this.value[0]
      this.form.endTime = this.value[1]
    },
    // 上一页
    handleSizeChange(val) {
      this.form.pageDate.pageSize = val
      this.onSubmit()
    },
    // 下一页
    handleCurrentChange(val) {
      this.form.pageDate.pageNum = val
      this.onSubmit()
    },
    // 重置
    khClear() {
      Object.keys(this.form).forEach((key) => {
        if (key !== 'pageDate' && key !== 'networkNameId') {
          this.form[key] = ''
        }
      })
      this.tableData = []
      this.value = ''
      this.total = ''
      this.current = ''
      this.pages = ''
      this.width = 1207
    },
    // 查询
    async onSubmit() {
      const params = {}
      Object.keys(this.form).forEach(key => {
        if (this.form[key]) {
          params[key] = this.form[key]
        }
      })
      const res = await NewSheetRebateApi(params)
      console.log(res)
      this.tableData = res.data.data
      this.total = res.data.total
      this.current = res.data.current
      this.pages = res.data.pages
    },
    changeType() {
      if (this.form.objectType === '1') {
        this.width = 1207
      } else {
        this.width = 1627
      }
      this.tableData = []
      this.form.contractAreaNameId = ''
      this.form.bigClientId = ''
      this.form.UCodeMerchantId = ''
      this.total = ''
      this.current = ''
      this.pages = ''
    },
    // U码商家名列表
    async UCode() {
      const res = await UCodeApi()
      console.log(res)
      this.UCodeList = res.data
    },
    // 大客户名列表
    async ClientTag() {
      const res = await ClientTagApi()
      console.log(res)

      this.ClientTagList = res.data
    },
    // 承包区列表
    async ShowCoverArea() {
      const res = await ShowCoverAreaApi()
      console.log(res)

      this.ShowCoverAreaList = res.data
    }
  }
}

</script>
<style  scoped lang="scss">
.tit {
  display: flex;

  .tex1 {
    margin-right: 48px;
    font-size: 16px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;
    background: #fff;
    border: 1px #fff solid;
  }

  .active {
    font-family: Source Han Sans CN;
    font-weight: 700;
    color: #2087d0;
    position: relative;
  }

  .active::before {
    position: absolute;
    content: '';
    width: 110px;
    height: 2px;
    background: #2087d0;
    border-radius: 1px;
    bottom: -20px;
    left: 50%;
    transform: translate(-50%);
  }
}

.head {
  padding: 30px;
}

.title {
  font-size: 16px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
  margin-top: 20px;
}

.line {
  height: 1px;
  background: #d8d8d8;
  border-radius: 1px;
  margin-top: 19px;
}

.title1 {
  .text {
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #666666;

    .input {
      width: 286px;
      height: 36px;
      background: #ffffff;
      border-radius: 4px;
    }

    .input1 {
      width: 708px;
      height: 36px;
      background: #ffffff;
      border: 1px solid #b4b4b4;
      border-radius: 4px;
    }
  }
}

.title2 {
  font-size: 18px;
  font-family: Source Han Sans CN;
  font-weight: 400;
  color: #666666;
}
</style>
